package com.suse.boss.mapper;


import com.suse.boss.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface UserMapper {

    @Select( "select * from user" )
    public List listAll( );

    @Select( "select _id,username,header from user" )
    public List<User> listAllHeader( );

    @Select( "select * from user where _id=#{id}" )
    public User findOneById(int id);

    @Select( "select * from user where username=#{username}" )
    public User findOne(String username);

    @Select( "select * from user where username=#{username} and password=#{password}" )
    public User login(String username, String password);

    @Options(useGeneratedKeys = true,keyProperty = "_id",keyColumn = "_id")//加入该注解可以保持对象后，查看对象插入id
    @Insert( "insert into user ( username,password,type) values ( #{user.username} , #{user.password} , #{user.type} ) " )
    public int saveUser(@Param( "user" ) User user);

    @Update( "update user set company=#{user.company},salary=#{user.salary},header=#{user.header},post = #{user.post} ,info = #{user.info} where _id=#{id} " )
    public int updateUser(User user,long id);

    @Select( "select * from user where type=#{type}" )
    public List<User> listByType(String type);
}
